//
//  MineTableViewController.m
//  InSuger
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 Dior_3g. All rights reserved.
//

#import "MineTableViewController.h"
#import "SetUpViewController.h"
#import "CollectionViewController.h"
#import "calendarViewController.h"

@interface MineTableViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSMutableArray *tableArray;

@end

@implementation MineTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createTableView];
    [self menuButtonCreateData];
    [self leftButton];
    
    
    @weakify(self);
    [self addColorChangedBlock:^{
        @strongify(self);
        self.tableView.nightBackgroundColor = UIColorFromRGB(0x343434);
        self.tableView.nightSeparatorColor = UIColorFromRGB(0x313131);
        self.navigationController.navigationBar.nightBarTintColor = UIColorFromRGB(0x444444);
        self.navigationItem.leftBarButtonItem.nightTintColor = [UIColor whiteColor];
        self.navigationItem.rightBarButtonItem.nightTintColor = [UIColor whiteColor];
    }];
        self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    self.tableView.backgroundColor = [UIColor whiteColor];
}
- (void)leftButton{
    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(0, 0, 20, 18);
    [menuBtn setBackgroundImage:[UIImage imageNamed:@"iconfont-rili.png"] forState:UIControlStateNormal];
    [menuBtn addTarget:self action:@selector(openCalendar) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:menuBtn];
}
- (void)menuButtonCreateData
{
    self.navigationItem.title = @"我的";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(0, 0, 20, 18);
    [menuBtn setBackgroundImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
    [menuBtn addTarget:self action:@selector(openOrCloseLeftList) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:menuBtn];
}
- (void)openCalendar{
    calendarViewController *calendarVC = [[calendarViewController alloc] init];
    calendarVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:calendarVC animated:YES];
}
- (void)openOrCloseLeftList
{
    SetUpViewController * suVC = [[SetUpViewController alloc] init];
    suVC.hidesBottomBarWhenPushed = YES;// 6666 写在跳转前面
    [self.navigationController pushViewController:suVC animated:YES];
}


- (void)createTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.size.mas_equalTo(self.view);
        
    }];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"my"];

    UIImageView *headerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 10 * 3)];
    self.tableView.tableHeaderView = headerView;
    headerView.image = [UIImage imageNamed:@"background.jpg"];
    
    self.tableArray = [NSMutableArray arrayWithObjects:@"收藏", @"夜间模式", @"清除缓存", nil];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.tableArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"my" forIndexPath:indexPath];
    
//    if (indexPath.row == 0) {
//        cell.imageView.image = [UIImage imageNamed:@"collection.png"];
//    } else if (indexPath.row == 1) {
//        cell.imageView.image = [UIImage imageNamed:@"night.png"];
//    } else if (indexPath.row == 2) {
//        cell.imageView.image = [UIImage imageNamed:@"clean.png"];
//    }
    
    cell.textLabel.text = self.tableArray[indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        CollectionViewController *collectionVC = [[CollectionViewController alloc] init];
        [self.navigationController pushViewController:collectionVC animated:YES];
    } else if (indexPath.row == 1) {
        
        if ([DKNightVersionManager currentThemeVersion] == DKThemeVersionNight) {
                [DKNightVersionManager dawnComing];
        } else {
                [DKNightVersionManager nightFalling];
        }
    } else if (indexPath.row == 2) {
        
        [AlertController createAlertTitle:@"提示信息" alertMessage:@"是否清除缓存" cancelTitle:@"取消" doneTitle:@"确认" viewController:self block:^(id block) {
            
            [Save deleteModel];
            
        }];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
